#override("css")
<link href="#springUrl('/static/css/bootstrap.min.css')" rel="stylesheet">
#end

#override("body")
<body class="white-bg">
<form id="baseForm"  class="form-horizontal m-t" autocomplete="off" data-validator-option="{timely:2, theme:'default', focusCleanup:true}">
	<div class="wrapper wrapper-content form-item">
		<div class="panel panel-default">
			<div class="row">
				<input type="hidden" name="id" value="$!{sysMenu.id}">

				<br />
				<div class="col-xs-12">
					<div class="form-group">
						<label class="col-md-2 control-label">菜单类型:</label>
						<div class="col-md-4">
							<div class="radio i-checks">
								<label><input type="radio" id="isDir" name="type" value="-1" #if($!sysMenu.type eq '-1') checked="" #else '' #end><i></i>目录</label>
								<label><input type="radio" id="isMenu" name="type" value="0" #if($!sysMenu.type eq '0') checked="" #else '' #end> <i></i>菜单</label>
								<label><input type="radio" id="isBtn" name="type" value="1" #if($!sysMenu.type eq '1') checked="" #else '' #end data-rule="checked"> <i></i>功能</label>
							</div>
						</div>
					</div>
				</div>
				<div class="col-xs-12">
					<div class="form-group">
						<label class="col-md-2 control-label">菜单名称:</label>
						<div class="col-md-4">
							<input type="text" class="form-control" name="name" value="$!{sysMenu.name}" placeholder="请输入菜单名称" data-rule="菜单名称:required;length(1~100)">
						</div>
					</div>
				</div>
				<div class="col-xs-12">
					<div class="form-group">
						<label class="col-md-2 control-label">上级菜单:</label>
						<div class="col-md-4">
							<input type=text id="parentName" name="parentName" class="form-control" value="$!{sysMenu.parentName}" onclick="showDialog()" readonly="readonly" data-rule="上级菜单:required">
							<input type="hidden" id="parentId" name="parentId" value="$!{sysMenu.parentId}">
						</div>
					</div>
				</div>
				<div class="col-xs-12">
					<div class="form-group">
						<label class="col-md-2 control-label">菜单地址:</label>
						<div class="col-md-4">
							<input type="text" class="form-control" name="url" value="$!{sysMenu.url}" placeholder="请输入菜单地址" data-rule="当菜单类型不为目录时,菜单地址:required(#isMenu:checked,#isBtn:checked);length(1~200)">
						</div>
					</div>
				</div>
				<div class="col-xs-12">
					<div class="form-group">
						<label class="col-md-2 control-label">菜单编码:</label>
						<div class="col-md-4">
							<input type="text" class="form-control" name="perms" value="$!{sysMenu.perms}" placeholder="请输入菜单编码" data-rule="当菜单类型不为目录时,菜单编码:required(#isMenu:checked,#isBtn:checked);length(1~200)">
						</div>
					</div>
				</div>
				<div class="col-xs-12">
					<div class="form-group">
						<label class="col-md-2 control-label">菜单图标:</label>
						<div class="col-md-4">
							<input type="text" class="form-control" name="icon" value="$!{sysMenu.icon}" placeholder="请输入菜单图标" data-rule="当菜单类型为目录时,菜单图标:required(#isDir:checked);length(1~30)">
							<code style="margin-top:4px;display: block;">获取图标：http://fontawesome.io/icons/</code>
						</div>
					</div>
				</div>
				<div class="col-xs-12">
					<div class="form-group">
						<label class="col-md-2 control-label">是否可用:</label>
						<div class="col-md-4">
							<select class="form-control" name="state" data-rule="required">
								<option value="0">可用</option>
								<option value="1">不可用</option>
							</select>
						</div>
					</div>
				</div>
				<div class="col-xs-12">
					<div class="form-group">
						<label class="col-md-2 control-label">排序:</label>
						<div class="col-md-4">
							<input type="number" class="form-control" name="sort" value="$!{sysMenu.sort}" placeholder="请输入序号" data-rule="required:integer[+]:length[~3];sort">
						</div>
					</div>
				</div>
				<div class="col-xs-12">
					<div class="form-group">
						<label class="col-md-2 control-label">描述信息:</label>
						<div class="col-md-4">
							<textarea class="form-control" name="description" placeholder="请输入描述信息" data-rule="描述信息:length(~200)">$!{sysMenu.description}</textarea>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</form>
</body>
#end

#override("js")
<script type="text/javascript">
	// 页面加载的时候调用的js
	$(function () {
		if ("$!{action}" == "doView") {
			$('input,select,textarea,checkbox,radio', $('form[id="baseForm"]')).attr('disabled', true);
		}
	});

	// 初始化表单验证及提交
	$("#baseForm").validator({
		focusCleanup: true,
		// 验证成功
		valid: function (form) {
			var me = this;
			// 提交表单之前，hold住表单，防止重复提交
			me.holdSubmit();

			$.ajax({
				url: "#springUrl('/sys/sysMenu/doEdit')",
				data: $(form).serialize(),
				type: "POST",
				success: function (data) {
					if (data.success) {
						parent.refreshTable();
						parent.layer.alert('处理数据成功', {icon: 1}, function () {
							parent.reloadPage();
							parent.layer.closeAll();
						});
					} else {
						parent.layer.alert(data.message, {icon: 2}, function (index) {
							//失败,提交表单成功后,释放hold,如果不释放hold,就变成了只能提交一次的表单
							me.holdSubmit(false);
							parent.layer.close(index);
						});
					}
				}
			});
		}
	});
	// 调用方法实现保存
	function save() {
		// 手工触发表单验证
		$("#baseForm").trigger('validate');
	}
</script>

<script type="text/javascript">
	// 转到显示选择表类型树页面
	function showDialog() {
		var parentId = $("#parentId").val();
		var url = "#springUrl('/sys/sysMenu/toTree?parentId="+parentId+"')";
		layer_show_btn("选择上级菜单", url, 400, null);
	}

	function getMaxSortByPId(parentId) {
		if(isNull(parentId)) return;

		$.ajax({
			url:"#springUrl('/sys/sysMenu/getMaxSortByPId/')" + parentId,
			data: "json",
			success : function(data) {
				if (data.success) {
					$("input[name='sort']").val(data.data);
				} else {
					alert("fdsafdsa");
				}
			}
		});
	}
</script>
#end
#extends("/common/base.html")